/*
 * Created on Nov 17, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package MethodCatcher;

import java.awt.AWTEvent;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.SwingUtilities;

import clock.Translation;


/**
 * @author Jayanth Recherla
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class EventsGenerator{
	Translation translation;
	
	public EventsGenerator() {
		this(null);
	}
	
	public EventsGenerator(Translation translation) {
		this.translation = translation ;
	}
	
	public void fireMousePressed() throws Exception {
		Runnable eventFirer = new Runnable(){
			public void run() {
				AWTEvent event =  new MouseEvent(new JButton(), 0, 0, 0, 0, 0, 0, false);
				translation.mousePressed( (MouseEvent) event);
			}
		};
		SwingUtilities.invokeAndWait(eventFirer);
	}
	
	public void fireMouseReleased() throws Exception {
		Runnable eventFirer = new Runnable(){
			public void run() {
				AWTEvent event =  new MouseEvent(new JButton(), 0, 0, 0, 0, 0, 0, false);
				translation.mouseReleased ( (MouseEvent) event);
			}
		};
		SwingUtilities.invokeAndWait(eventFirer);
	}
	
	public void fireAction(final String command) throws Exception {
		Runnable eventFirer = new Runnable(){
			public void run() {
				AWTEvent event = new ActionEvent(this, 0, command, 0);
				translation.actionPerformed((ActionEvent)event);
			}
		};
		SwingUtilities.invokeAndWait(eventFirer);
	}

}
